package com.umeox.watch.moto.sos.task;

import android.os.AsyncTask;
import android.os.RemoteException;

import com.umeox.watch.moto.dataservice.interfaces.ILocation;
import com.umeox.watch.moto.dataservice.proxy.LocationProxy;


public class LocationTask {

    private ILocation mSosService;

    private LocationTask() {
        mSosService = LocationProxy.fetchBinder();
    }

    public static LocationTask createTask() {
        return new LocationTask();
    }

    public byte[] getLocation() throws RemoteException {
        return mSosService.requestLocation4Sos();
    }

    public void getLocationAsync(final LocationListener listener) {
        AsyncTask.execute(() -> {
            if (listener != null) {
                try {
                    listener.onResult(mSosService.requestLocation4Sos());
                } catch (RemoteException e) {
                    e.printStackTrace();
                }
            }
        });
    }

    public interface LocationListener {
        void onResult(byte[] data);
    }
}
